<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Soapcontroller extends CI_Controller {



	public function get_all_objects()
	{
		$orgid=1;//$this->session->userdata['OrgID'];

		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->readAllObjects(array('orgId'=>$orgid));
		//$result='[{"_objid":1,"objName":"Cell Phone","_orgId":1},{"_objid":2,"objName":"Laptop","_orgId":1},{"_objid":3,"objName":"Tablet","_orgId":1}]';
		echo $result->return;
	}

	public function get_object($param){

	}

	public function create_object() {
		$objname=$this->input->post("objname",TRUE);
		//$orgid=$this->session->userdata['OrgID'];

		$orgid=$this->session->userdata['OrgID'];
		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->createObject(array('orgId'=>$orgid,'objName'=>$objname));

		echo $result->return;

	}

	public function get_fields() {

		$objname=$this->input->post("objname",TRUE);
		$orgid=$this->session->userdata['OrgID'];
		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->read(array('orgId'=>$orgid,'objName'=>$objname));
		print_r($result->return);
	}

	public function create_field(){

		$objname=$this->input->post("objname",TRUE);
		$fieldnum=$this->input->post("fieldnum",TRUE);
		$fieldname=$this->input->post("fieldname",TRUE);
		$datatype=$this->input->post("datatype",TRUE);
		$reference=$this->input->post("reference",TRUE);
		$orgid=$this->session->userdata['OrgID'];
		$requestArray=array(
						'orgId'=>$orgid,
						'objName'=>$objname,
						'fieldName'=>$fieldname,
						'dataType'=>$datatype,
						'reference'=>$reference,
						'fieldNum'=>$fieldnum
			
		);

		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->createField($requestArray);
		echo $result->return;
			
	}

	public function update_object(){

		$orgid=$this->session->userdata['OrgID'];
		$objname=$this->input->post("objname",TRUE);
		$newobjname=$this->input->post("newobjname",TRUE);

		$requestArray=array(
								'orgId'=>$orgid,
								'objName'=>$objname,
								'newObjName'=>$newobjname
		);

		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->updateObject($requestArray);
		echo $result->return;
	}

	public function update_field(){
		$orgid=$this->session->userdata['OrgID'];
		$objname=$this->input->post("objname",TRUE);
		$fieldnum=$this->input->post("fieldnum",TRUE);
		$fieldname=$this->input->post("fieldname",TRUE);
		$datatype=$this->input->post("datatype",TRUE);
		$reference=$this->input->post("reference",TRUE);


		$requestArray=array(
						'orgId'=>$orgid,
						'objName'=>$objname,
						'fieldName'=>$fieldname,
						'dataType'=>$datatype,
						'reference'=>$reference,
						'updateFieldNum'=>$fieldnum
			
		);

		$objname=$this->input->post("objname",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->updateField($requestArray);
		print_r($result->return);
	}

	public function delete_object(){
		$orgid=$this->session->userdata['OrgID'];
		$objname=$this->input->post("objname",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->deleteObject(array('orgId'=>$orgid,'objName'=>$objname));
		print_r($result->return);
	}

	public function delete_field(){
		$orgid=$this->session->userdata['OrgID'];
		$objname=$this->input->post("objname",TRUE);
		$fieldname=$this->input->post("fieldname",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService?wsdl");
		$result=$client->deleteField(array('orgId'=>$orgid,'objName'=>$objname,'fieldName'=>$fieldname));
		print_r($result->return);


	}
	
	public function adddata(){
		$orgid=$this->session->userdata['OrgID'];
		
		$objid=$this->input->post("objid",TRUE);
		$fieldid=$this->input->post("fieldid",TRUE);
		$fieldval=$this->input->post("fieldval",TRUE);
		
		
		$client=new SoapClient("http://localhost:8080/SunShopWebServiceAsu/services/SunShopWebService2?wsdl");
		$result=$client->insertDataForObject(array('orgId'=>$orgid,'objId'=>$objid,'fieldId'=>$fieldid, 'fieldvalue'=>$fieldval));
		echo $result->return;
		
		//print_r(array('orgId'=>$orgid,'objId'=>$objid,'fieldId'=>$fieldid, 'fieldvalue'=>$fieldval));
	}

}